package com.demo.service.serviceImpl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.demo.entity.BillOrder;
import com.demo.mapper.BillOrderDao;
import com.demo.request.GetBillOrderReq;
import com.demo.service.BillOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @Description:
 * @author: fanfan
 * @date: 2018/7/4 10:29
 */
@Service
@Slf4j
public class BillOrderServiceImpl extends ServiceImpl<BillOrderDao,BillOrder> implements BillOrderService {
    @Override
    public Page getCount(GetBillOrderReq req) {
        Page page=new Page();
        page.setSize(req.getSize());
        page.setCurrent(req.getCurrent());
        EntityWrapper<BillOrder> wrapper=new EntityWrapper<>();
        wrapper.setSqlSelect("borrower_user_id as borrowerUserId","SUM(order_amt) as OrderAmt","sys_date as time");
        wrapper.groupBy("borrower_user_id");
        wrapper.orderBy("update_time",false);
        List<Map<String, Object>> maps = selectMaps(wrapper);
        Page<Map<String, Object>> mapPage = selectMapsPage(page, wrapper);
        mapPage.setTotal(maps.size());
        return mapPage;
    }

    @Override
    public Page test(GetBillOrderReq req) {
        Wrapper<BillOrder> con=new Condition();
        Page page=new Page();
        page.setCurrent(req.getCurrent());
        page.setSize(req.getSize());
        page.setTotal(selectCount(con));
        return selectPage(page,con);
    }
}
